<include file="public@header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('student/index')}">所有学生</a></li>
        <li><a href="{:url('student/add')}">添加学生</a></li>
    </ul>
    <form class="well form-inline margin-top-20"  method="get" action="{:url('student/index')}">
        学校名称：
        <select name="school_id" id="selectSchool" lay-filter="selectSchool" class="form-control">
            <option value="">--请选择学校--</option>
            <foreach name="school" item="vo">
                <php>$slelectedSchool = $vo['id']== $school_id?"selected":""</php>
                <option value="{$vo.id}" {$slelectedSchool}>{$vo.name}</option>
            </foreach>
        </select>
        班级名称：
        <select name="room_id" id="selectRoom" lay-filter="selectSchool" class="form-control">
            <option value="">--请选择班级--</option>
            <foreach name="room" item="vo">
                <php>$slelectedRoom = $vo['id']==$room_id?"selected":""</php>
                <option value="{$vo.id}" {$slelectedRoom}>{$vo.name}</option>
            </foreach>
        </select>
        学生姓名:
        <input type="text" class="form-control" name="name" style="width: 150px;" value="{:input('request.name/s')}" placeholder="请输入学生姓名">
        <input type="submit" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:url('stude[nt/index')}">清空</a>
        <a class="btn btn-danger" href="{:url('grade /index')}">查看成绩</a>
    </form>
    <div>
        <a class="btn btn-success" href="{:url('student/exportExcel')}">导出Excel</a>
        <a class="btn btn-success" id="import">导入Excel</a>
        <a class="btn btn-success" href="{:url('student/download')}">下载导入模板</a>
    </div>
    <form method="post" class="js-ajax-form margin-top-20" action="{:url('student/delAll')}">
        <div class="table-actions">
            <button class="btn btn-sm btn-danger js-ajax-submit" type="submit"
                    data-action="{:url('student/delAll')}" data-subcheck="true">批量删除
            </button>
        </div>
        <table class="table table-hover table-bordered">
            <thead>
                <tr>
                    <th width="16"><label><input type="checkbox" class="js-check-all" data-direction="x"
                                                 data-checklist="js-check-x"></label></th>
                    <th width="30">ID</th>
                    <th>图片</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>手机号</th>
                    <th>身份证号</th>
                    <th>班级名称</th>
                    <th>学校名称</th>
                    <th>修改时间</th>
                    <th>创建时间</th>
                    <th width="160">{:lang('ACTIONS')}</th>
                </tr>
            </thead>
           <tbody>
           <foreach name="student" item="vo">
               <tr>
                   <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                              value="{$vo.id}"></td>
                   <td>{$key+1}</td>
                   <th><img src="/upload/{$vo.image}" width="50px"></th>
                   <td>{$vo.name}</td>
                   <td>
                       <if $vo.sex==1>
                           男
                        <else/>
                            女
                        </if>
                    </td>
                   <td>{$vo.age}</td>
                   <td>{$vo.mobile}</td>
                   <td>{$vo.idcard}</td>
                   <td>{$vo.room_name}</td>
                   <td>{$vo.school_name}</td>
                   <td>{$vo.update_time}</td>
                   <td>{$vo.create_time}</td>
                   <td>
                       <a class="btn btn-xs btn-success" href="{:url('student/grade',array('id'=>$vo['id']))}">成绩</a>
                       <a class="btn btn-xs btn-success" href="{:url('student/edit',array('id'=>$vo['id']))}">编辑</a>
                       <a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('student/delete',array('id'=>$vo['id']))}">删除</a>
                   </td>
               </tr>
           </foreach>
           </tbody>
        </table>
    <div class="pagination">{$page}</div>
    <div style="text-align: center;">
        当 前 第 {$student->currentPage()} 条 数 据，共 {$student->total()} 条 数 据，共 {$student->lastPage()} 页
    </div>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/layui/layui.all.js"></script>
<script>
    layui.use('upload', function() {
        var upload = layui.upload;
        var uploadInst=upload.render({
        //要监听的元素
            elem:"#import",
            url:"{:url('student/importExcel')}",
            accept:'file',
            //请求成功时
            done:function (res) {
                layer.msg('成功导入'+res.success+'条数据');
                setTimeout(function () {
                    location.reload();
                },2000)
            }
         });
    });
    //触发选择学校时去查对应的班级
    $(function () {
        $('#selectSchool').change('click',function () {
            var schoolId=$('#selectSchool').val();
            $.ajax({
                url:"{:url('student/getRoom')}",
                type:"POST",
                data:{schoolId:schoolId},
                success:function (res) {
                    $('#selectRoom').html(res);
                }
            });
        });
    });
    $(function () {
        $('#selectRoom').change('click',function () {
            var roomId=$('#selectRoom').val();
            $.ajax({
                url:"{:url('student/getStudent')}",
                type:"POST",
                data:{roomId:roomId},
                success:function (res) {
                    $('#student_id').html(res);
                }
            });
        });
    }) 
</script>
</body>
</html>